package com.burgeon.backend.SHOP.rest;
/**
 * 新增评论
 */

import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.SHOP.entity.Comment;
import com.burgeon.backend.SHOP.entity.CommentItem;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class CreateComment extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public CreateComment(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }
    /**
     * 发送并接收字符
     */
    public String getData(Comment comment,String prcode) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(comment,prcode), url);
        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        String message = new JSONArray(str).getJSONObject(0).getString("message");
        if (!"0".equals(code)) {
            throw new Exception(message);
        }
        return new JSONArray(str).getJSONObject(0).getString("objectid");
    }

    private MultiValueMap Data(Comment comment,String code) {
        HashMap params = new HashMap();
        params.put("'YC_RETAIL_ID__DOCNO'",comment.getOrderId());
        params.put("C_VIP_ID__CARDNO",comment.getVip());
        params.put("M_PRODUCT_ID__NAME",code);
        params.put("PRODUCT",comment.getScore1());//商品质量
        params.put("COMFORTABLE",comment.getScore2());//舒适度
        params.put("PACKING",comment.getScore3());//快递包装
        params.put("DELIVERY_SPEED",comment.getScore4());//送货速度
        params.put("DESCRIPTION",comment.getComment());//评论

        params.put("table", "YC_VALUATION");//表名

        return DATA("ObjectCreate", params, account, password);
    }
    public static void main(String[] args) {

        CreateComment g = new CreateComment("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        Comment comment = new Comment();
        comment.setOrderId("RE2004010000001");
        comment.setVip("17732141036");
        comment.setScore1("1");
        comment.setScore2("2");
        comment.setScore3("3");
        comment.setScore4("4");
        CommentItem commentItem = new CommentItem();
        commentItem.setCode("XMCDB019999");
        List a = new ArrayList();
        a.add(commentItem);
        comment.setCommentItems(a);
        try {
            g.getData(comment,"XMCDB");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
